home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Interfaces&Libraries / Universal / Interfaces / CIncludes / QD3DMath.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  26.8 KB  |  911 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        QD3DMath.h
  3.  
  4.      Contains:    Math & matrix routines and definitions.                            
  5.  
  6.      Version:    Technology:    Quickdraw 3D 1.5.4
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1995-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __QD3DMATH__
  18. #define __QD3DMATH__
  19.  
  20. #ifndef __QD3D__
  21. #include <QD3D.h>
  22. #endif
  23.  
  24. #include <float.h>
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=power
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47. #if PRAGMA_ENUM_ALWAYSINT
  48.     #pragma enumsalwaysint on
  49. #elif PRAGMA_ENUM_OPTIONS
  50.     #pragma option enum=int
  51. #elif PRAGMA_ENUM_PACK
  52.     #if __option(pack_enums)
  53.         #define PRAGMA_ENUM_PACK__QD3DMATH__
  54.     #endif
  55.     #pragma options(!pack_enums)
  56. #endif
  57.  
  58. /******************************************************************************
  59.  **                                                                             **
  60.  **                            Constant Definitions                             **
  61.  **                                                                             **
  62.  *****************************************************************************/
  63. /*
  64.  *  Real zero definition
  65.  */
  66.  
  67. #ifdef FLT_EPSILON
  68.     #define kQ3RealZero            (FLT_EPSILON)
  69. #else
  70.     #define kQ3RealZero            ((float)1.19209290e-07)
  71. #endif
  72.  
  73. #ifdef FLT_MAX
  74.     #define kQ3MaxFloat            (FLT_MAX)
  75. #else
  76.     #define kQ3MaxFloat            ((float)3.40282347e+38)
  77. #endif
  78.  
  79. /*
  80.  *  Values of PI
  81.  */
  82. #define kQ3Pi                     ((float)3.1415926535898)
  83. #define kQ32Pi                     ((float)(2.0 * 3.1415926535898))
  84. #define kQ3PiOver2                ((float)(3.1415926535898 / 2.0))
  85. #define kQ33PiOver2                ((float)(3.0 * 3.1415926535898 / 2.0))
  86.  
  87.  
  88. /******************************************************************************
  89.  **                                                                             **
  90.  **                            Miscellaneous Functions                             **
  91.  **                                                                             **
  92.  *****************************************************************************/
  93. #define Q3Math_DegreesToRadians(x)    ((float)((x) *  kQ3Pi / 180.0))
  94. #define Q3Math_RadiansToDegrees(x)    ((float)((x) * 180.0 / kQ3Pi))
  95. #define Q3Math_Min(x,y)                ((x) <= (y) ? (x) : (y))
  96. #define Q3Math_Max(x,y)                ((x) >= (y) ? (x) : (y))
  97.  
  98. /******************************************************************************
  99.  **                                                                             **
  100.  **                            Point and Vector Creation                         **
  101.  **                                                                             **
  102.  *****************************************************************************/
  103. EXTERN_API_C( TQ3Point2D *)
  104. Q3Point2D_Set                    (TQ3Point2D *            point2D,
  105.                                  float                     x,
  106.                                  float                     y);
  107.  
  108. EXTERN_API_C( TQ3Param2D *)
  109. Q3Param2D_Set                    (TQ3Param2D *            param2D,
  110.                                  float                     u,
  111.                                  float                     v);
  112.  
  113. EXTERN_API_C( TQ3Point3D *)
  114. Q3Point3D_Set                    (TQ3Point3D *            point3D,
  115.                                  float                     x,
  116.                                  float                     y,
  117.                                  float                     z);
  118.  
  119. EXTERN_API_C( TQ3RationalPoint3D *)
  120. Q3RationalPoint3D_Set            (TQ3RationalPoint3D *    point3D,
  121.                                  float                     x,
  122.                                  float                     y,
  123.                                  float                     w);
  124.  
  125. EXTERN_API_C( TQ3RationalPoint4D *)
  126. Q3RationalPoint4D_Set            (TQ3RationalPoint4D *    point4D,
  127.                                  float                     x,
  128.                                  float                     y,
  129.                                  float                     z,
  130.                                  float                     w);
  131.  
  132. EXTERN_API_C( TQ3Vector2D *)
  133. Q3Vector2D_Set                    (TQ3Vector2D *            vector2D,
  134.                                  float                     x,
  135.                                  float                     y);
  136.  
  137. EXTERN_API_C( TQ3Vector3D *)
  138. Q3Vector3D_Set                    (TQ3Vector3D *            vector3D,
  139.                                  float                     x,
  140.                                  float                     y,
  141.                                  float                     z);
  142.  
  143. EXTERN_API_C( TQ3PolarPoint *)
  144. Q3PolarPoint_Set                (TQ3PolarPoint *        polarPoint,
  145.                                  float                     r,
  146.                                  float                     theta);
  147.  
  148. EXTERN_API_C( TQ3SphericalPoint *)
  149. Q3SphericalPoint_Set            (TQ3SphericalPoint *    sphericalPoint,
  150.                                  float                     rho,
  151.                                  float                     theta,
  152.                                  float                     phi);
  153.  
  154.  
  155. /******************************************************************************
  156.  **                                                                             **
  157.  **                    Point and Vector Dimension Conversion                     **
  158.  **                                                                             **
  159.  *****************************************************************************/
  160. EXTERN_API_C( TQ3Point3D *)
  161. Q3Point2D_To3D                    (const TQ3Point2D *        point2D,
  162.                                  TQ3Point3D *            result);
  163.  
  164. EXTERN_API_C( TQ3Point2D *)
  165. Q3RationalPoint3D_To2D            (const TQ3RationalPoint3D * point3D,
  166.                                  TQ3Point2D *            result);
  167.  
  168. EXTERN_API_C( TQ3RationalPoint4D *)
  169. Q3Point3D_To4D                    (const TQ3Point3D *        point3D,
  170.                                  TQ3RationalPoint4D *    result);
  171.  
  172. EXTERN_API_C( TQ3Point3D *)
  173. Q3RationalPoint4D_To3D            (const TQ3RationalPoint4D * point4D,
  174.                                  TQ3Point3D *            result);
  175.  
  176. EXTERN_API_C( TQ3Vector3D *)
  177. Q3Vector2D_To3D                    (const TQ3Vector2D *    vector2D,
  178.                                  TQ3Vector3D *            result);
  179.  
  180. EXTERN_API_C( TQ3Vector2D *)
  181. Q3Vector3D_To2D                    (const TQ3Vector3D *    vector3D,
  182.                                  TQ3Vector2D *            result);
  183.  
  184.  
  185. /******************************************************************************
  186.  **                                                                             **
  187.  **                            Point Subtraction                                 **
  188.  **                                                                             **
  189.  *****************************************************************************/
  190. EXTERN_API_C( TQ3Vector2D *)
  191. Q3Point2D_Subtract                (const TQ3Point2D *        p1,
  192.                                  const TQ3Point2D *        p2,
  193.                                  TQ3Vector2D *            result);
  194.  
  195. EXTERN_API_C( TQ3Vector2D *)
  196. Q3Param2D_Subtract                (const TQ3Param2D *        p1,
  197.                                  const TQ3Param2D *        p2,
  198.                                  TQ3Vector2D *            result);
  199.  
  200. EXTERN_API_C( TQ3Vector3D *)
  201. Q3Point3D_Subtract                (const TQ3Point3D *        p1,
  202.                                  const TQ3Point3D *        p2,
  203.                                  TQ3Vector3D *            result);
  204.  
  205.  
  206. /******************************************************************************
  207.  **                                                                             **
  208.  **                            Point Distance                                     **
  209.  **                                                                             **
  210.  *****************************************************************************/
  211. EXTERN_API_C( float )
  212. Q3Point2D_Distance                (const TQ3Point2D *        p1,
  213.                                  const TQ3Point2D *        p2);
  214.  
  215. EXTERN_API_C( float )
  216. Q3Point2D_DistanceSquared        (const TQ3Point2D *        p1,
  217.                                  const TQ3Point2D *        p2);
  218.  
  219.  
  220. EXTERN_API_C( float )
  221. Q3Param2D_Distance                (const TQ3Param2D *        p1,
  222.                                  const TQ3Param2D *        p2);
  223.  
  224. EXTERN_API_C( float )
  225. Q3Param2D_DistanceSquared        (const TQ3Param2D *        p1,
  226.                                  const TQ3Param2D *        p2);
  227.  
  228.  
  229. EXTERN_API_C( float )
  230. Q3RationalPoint3D_Distance        (const TQ3RationalPoint3D * p1,
  231.                                  const TQ3RationalPoint3D * p2);
  232.  
  233. EXTERN_API_C( float )
  234. Q3RationalPoint3D_DistanceSquared (const TQ3RationalPoint3D * p1,
  235.                                  const TQ3RationalPoint3D * p2);
  236.  
  237.  
  238. EXTERN_API_C( float )
  239. Q3Point3D_Distance                (const TQ3Point3D *        p1,
  240.                                  const TQ3Point3D *        p2);
  241.  
  242. EXTERN_API_C( float )
  243. Q3Point3D_DistanceSquared        (const TQ3Point3D *        p1,
  244.                                  const TQ3Point3D *        p2);
  245.  
  246.  
  247. EXTERN_API_C( float )
  248. Q3RationalPoint4D_Distance        (const TQ3RationalPoint4D * p1,
  249.                                  const TQ3RationalPoint4D * p2);
  250.  
  251. EXTERN_API_C( float )
  252. Q3RationalPoint4D_DistanceSquared (const TQ3RationalPoint4D * p1,
  253.                                  const TQ3RationalPoint4D * p2);
  254.  
  255.  
  256. /******************************************************************************
  257.  **                                                                             **
  258.  **                            Point Relative Ratio                             **
  259.  **                                                                             **
  260.  *****************************************************************************/
  261. EXTERN_API_C( TQ3Point2D *)
  262. Q3Point2D_RRatio                (const TQ3Point2D *        p1,
  263.                                  const TQ3Point2D *        p2,
  264.                                  float                     r1,
  265.                                  float                     r2,
  266.                                  TQ3Point2D *            result);
  267.  
  268. EXTERN_API_C( TQ3Param2D *)
  269. Q3Param2D_RRatio                (const TQ3Param2D *        p1,
  270.                                  const TQ3Param2D *        p2,
  271.                                  float                     r1,
  272.                                  float                     r2,
  273.                                  TQ3Param2D *            result);
  274.  
  275. EXTERN_API_C( TQ3Point3D *)
  276. Q3Point3D_RRatio                (const TQ3Point3D *        p1,
  277.                                  const TQ3Point3D *        p2,
  278.                                  float                     r1,
  279.                                  float                     r2,
  280.                                  TQ3Point3D *            result);
  281.  
  282. EXTERN_API_C( TQ3RationalPoint4D *)
  283. Q3RationalPoint4D_RRatio        (const TQ3RationalPoint4D * p1,
  284.                                  const TQ3RationalPoint4D * p2,
  285.                                  float                     r1,
  286.                                  float                     r2,
  287.                                  TQ3RationalPoint4D *    result);
  288.  
  289.  
  290. /******************************************************************************
  291.  **                                                                             **
  292.  **                    Point / Vector Addition    & Subtraction                     **
  293.  **                                                                             **
  294.  *****************************************************************************/
  295. EXTERN_API_C( TQ3Point2D *)
  296. Q3Point2D_Vector2D_Add            (const TQ3Point2D *        point2D,
  297.                                  const TQ3Vector2D *    vector2D,
  298.                                  TQ3Point2D *            result);
  299.  
  300. EXTERN_API_C( TQ3Param2D *)
  301. Q3Param2D_Vector2D_Add            (const TQ3Param2D *        param2D,
  302.                                  const TQ3Vector2D *    vector2D,
  303.                                  TQ3Param2D *            result);
  304.  
  305. EXTERN_API_C( TQ3Point3D *)
  306. Q3Point3D_Vector3D_Add            (const TQ3Point3D *        point3D,
  307.                                  const TQ3Vector3D *    vector3D,
  308.                                  TQ3Point3D *            result);
  309.  
  310. EXTERN_API_C( TQ3Point2D *)
  311. Q3Point2D_Vector2D_Subtract        (const TQ3Point2D *        point2D,
  312.                                  const TQ3Vector2D *    vector2D,
  313.                                  TQ3Point2D *            result);
  314.  
  315. EXTERN_API_C( TQ3Param2D *)
  316. Q3Param2D_Vector2D_Subtract        (const TQ3Param2D *        param2D,
  317.                                  const TQ3Vector2D *    vector2D,
  318.                                  TQ3Param2D *            result);
  319.  
  320. EXTERN_API_C( TQ3Point3D *)
  321. Q3Point3D_Vector3D_Subtract        (const TQ3Point3D *        point3D,
  322.                                  const TQ3Vector3D *    vector3D,
  323.                                  TQ3Point3D *            result);
  324.  
  325.  
  326. /******************************************************************************
  327.  **                                                                             **
  328.  **                                Vector Scale                                 **
  329.  **                                                                             **
  330.  *****************************************************************************/
  331. EXTERN_API_C( TQ3Vector2D *)
  332. Q3Vector2D_Scale                (const TQ3Vector2D *    vector2D,
  333.                                  float                     scalar,
  334.                                  TQ3Vector2D *            result);
  335.  
  336. EXTERN_API_C( TQ3Vector3D *)
  337. Q3Vector3D_Scale                (const TQ3Vector3D *    vector3D,
  338.                                  float                     scalar,
  339.                                  TQ3Vector3D *            result);
  340.  
  341.  
  342. /******************************************************************************
  343.  **                                                                             **
  344.  **                                Vector Length                                 **
  345.  **                                                                             **
  346.  *****************************************************************************/
  347. EXTERN_API_C( float )
  348. Q3Vector2D_Length                (const TQ3Vector2D *    vector2D);
  349.  
  350. EXTERN_API_C( float )
  351. Q3Vector3D_Length                (const TQ3Vector3D *    vector3D);
  352.  
  353.  
  354. /******************************************************************************
  355.  **                                                                             **
  356.  **                                Vector Normalize                             **
  357.  **                                                                             **
  358.  *****************************************************************************/
  359. EXTERN_API_C( TQ3Vector2D *)
  360. Q3Vector2D_Normalize            (const TQ3Vector2D *    vector2D,
  361.                                  TQ3Vector2D *            result);
  362.  
  363. EXTERN_API_C( TQ3Vector3D *)
  364. Q3Vector3D_Normalize            (const TQ3Vector3D *    vector3D,
  365.                                  TQ3Vector3D *            result);
  366.  
  367.  
  368. /******************************************************************************
  369.  **                                                                             **
  370.  **                    Vector/Vector Addition and Subtraction                     **
  371.  **                                                                             **
  372.  *****************************************************************************/
  373. EXTERN_API_C( TQ3Vector2D *)
  374. Q3Vector2D_Add                    (const TQ3Vector2D *    v1,
  375.                                  const TQ3Vector2D *    v2,
  376.                                  TQ3Vector2D *            result);
  377.  
  378. EXTERN_API_C( TQ3Vector3D *)
  379. Q3Vector3D_Add                    (const TQ3Vector3D *    v1,
  380.                                  const TQ3Vector3D *    v2,
  381.                                  TQ3Vector3D *            result);
  382.  
  383.  
  384. EXTERN_API_C( TQ3Vector2D *)
  385. Q3Vector2D_Subtract                (const TQ3Vector2D *    v1,
  386.                                  const TQ3Vector2D *    v2,
  387.                                  TQ3Vector2D *            result);
  388.  
  389. EXTERN_API_C( TQ3Vector3D *)
  390. Q3Vector3D_Subtract                (const TQ3Vector3D *    v1,
  391.                                  const TQ3Vector3D *    v2,
  392.                                  TQ3Vector3D *            result);
  393.  
  394.  
  395. /******************************************************************************
  396.  **                                                                             **
  397.  **                                Cross Product                                 **
  398.  **                                                                             **
  399.  *****************************************************************************/
  400. EXTERN_API_C( float )
  401. Q3Vector2D_Cross                (const TQ3Vector2D *    v1,
  402.                                  const TQ3Vector2D *    v2);
  403.  
  404. EXTERN_API_C( TQ3Vector3D *)
  405. Q3Vector3D_Cross                (const TQ3Vector3D *    v1,
  406.                                  const TQ3Vector3D *    v2,
  407.                                  TQ3Vector3D *            result);
  408.  
  409. EXTERN_API_C( TQ3Vector3D *)
  410. Q3Point3D_CrossProductTri        (const TQ3Point3D *        point1,
  411.                                  const TQ3Point3D *        point2,
  412.                                  const TQ3Point3D *        point3,
  413.                                  TQ3Vector3D *            crossVector);
  414.  
  415.  
  416. /******************************************************************************
  417.  **                                                                             **
  418.  **                                Dot Product                                     **
  419.  **                                                                             **
  420.  *****************************************************************************/
  421. EXTERN_API_C( float )
  422. Q3Vector2D_Dot                    (const TQ3Vector2D *    v1,
  423.                                  const TQ3Vector2D *    v2);
  424.  
  425. EXTERN_API_C( float )
  426. Q3Vector3D_Dot                    (const TQ3Vector3D *    v1,
  427.                                  const TQ3Vector3D *    v2);
  428.  
  429.  
  430. /******************************************************************************
  431.  **                                                                             **
  432.  **                        Point and Vector Transformation                         **
  433.  **                                                                             **
  434.  *****************************************************************************/
  435. EXTERN_API_C( TQ3Vector2D *)
  436. Q3Vector2D_Transform            (const TQ3Vector2D *    vector2D,
  437.                                  const TQ3Matrix3x3 *    matrix3x3,
  438.                                  TQ3Vector2D *            result);
  439.  
  440. EXTERN_API_C( TQ3Vector3D *)
  441. Q3Vector3D_Transform            (const TQ3Vector3D *    vector3D,
  442.                                  const TQ3Matrix4x4 *    matrix4x4,
  443.                                  TQ3Vector3D *            result);
  444.  
  445. EXTERN_API_C( TQ3Point2D *)
  446. Q3Point2D_Transform                (const TQ3Point2D *        point2D,
  447.                                  const TQ3Matrix3x3 *    matrix3x3,
  448.                                  TQ3Point2D *            result);
  449.  
  450. EXTERN_API_C( TQ3Param2D *)
  451. Q3Param2D_Transform                (const TQ3Param2D *        param2D,
  452.                                  const TQ3Matrix3x3 *    matrix3x3,
  453.                                  TQ3Param2D *            result);
  454.  
  455. EXTERN_API_C( TQ3Point3D *)
  456. Q3Point3D_Transform                (const TQ3Point3D *        point3D,
  457.                                  const TQ3Matrix4x4 *    matrix4x4,
  458.                                  TQ3Point3D *            result);
  459.  
  460. EXTERN_API_C( TQ3RationalPoint4D *)
  461. Q3RationalPoint4D_Transform        (const TQ3RationalPoint4D * point4D,
  462.                                  const TQ3Matrix4x4 *    matrix4x4,
  463.                                  TQ3RationalPoint4D *    result);
  464.  
  465. EXTERN_API_C( TQ3Status )
  466. Q3Point3D_To3DTransformArray    (const TQ3Point3D *        inPoint3D,
  467.                                  const TQ3Matrix4x4 *    matrix,
  468.                                  TQ3Point3D *            outPoint3D,
  469.                                  long                     numPoints,
  470.                                  unsigned long             inStructSize,
  471.                                  unsigned long             outStructSize);
  472.  
  473. EXTERN_API_C( TQ3Status )
  474. Q3Point3D_To4DTransformArray    (const TQ3Point3D *        inPoint3D,
  475.                                  const TQ3Matrix4x4 *    matrix,
  476.                                  TQ3RationalPoint4D *    outPoint4D,
  477.                                  long                     numPoints,
  478.                                  unsigned long             inStructSize,
  479.                                  unsigned long             outStructSize);
  480.  
  481. EXTERN_API_C( TQ3Status )
  482. Q3RationalPoint4D_To4DTransformArray (const TQ3RationalPoint4D * inPoint4D,
  483.                                  const TQ3Matrix4x4 *    matrix,
  484.                                  TQ3RationalPoint4D *    outPoint4D,
  485.                                  long                     numPoints,
  486.                                  unsigned long             inStructSize,
  487.                                  unsigned long             outStructSize);
  488.  
  489.  
  490. /******************************************************************************
  491.  **                                                                             **
  492.  **                                Vector Negation                                 **
  493.  **                                                                             **
  494.  *****************************************************************************/
  495. EXTERN_API_C( TQ3Vector2D *)
  496. Q3Vector2D_Negate                (const TQ3Vector2D *    vector2D,
  497.                                  TQ3Vector2D *            result);
  498.  
  499. EXTERN_API_C( TQ3Vector3D *)
  500. Q3Vector3D_Negate                (const TQ3Vector3D *    vector3D,
  501.                                  TQ3Vector3D *            result);
  502.  
  503.  
  504. /******************************************************************************
  505.  **                                                                             **
  506.  **                    Point conversion from cartesian to polar                 **
  507.  **                                                                             **
  508.  *****************************************************************************/
  509. EXTERN_API_C( TQ3PolarPoint *)
  510. Q3Point2D_ToPolar                (const TQ3Point2D *        point2D,
  511.                                  TQ3PolarPoint *        result);
  512.  
  513. EXTERN_API_C( TQ3Point2D *)
  514. Q3PolarPoint_ToPoint2D            (const TQ3PolarPoint *    polarPoint,
  515.                                  TQ3Point2D *            result);
  516.  
  517. EXTERN_API_C( TQ3SphericalPoint *)
  518. Q3Point3D_ToSpherical            (const TQ3Point3D *        point3D,
  519.                                  TQ3SphericalPoint *    result);
  520.  
  521. EXTERN_API_C( TQ3Point3D *)
  522. Q3SphericalPoint_ToPoint3D        (const TQ3SphericalPoint * sphericalPoint,
  523.                                  TQ3Point3D *            result);
  524.  
  525.  
  526. /******************************************************************************
  527.  **                                                                             **
  528.  **                            Point Affine Combinations                         **
  529.  **                                                                             **
  530.  *****************************************************************************/
  531. EXTERN_API_C( TQ3Point2D *)
  532. Q3Point2D_AffineComb            (const TQ3Point2D *        points2D,
  533.                                  const float *            weights,
  534.                                  unsigned long             nPoints,
  535.                                  TQ3Point2D *            result);
  536.  
  537. EXTERN_API_C( TQ3Param2D *)
  538. Q3Param2D_AffineComb            (const TQ3Param2D *        params2D,
  539.                                  const float *            weights,
  540.                                  unsigned long             nPoints,
  541.                                  TQ3Param2D *            result);
  542.  
  543. EXTERN_API_C( TQ3RationalPoint3D *)
  544. Q3RationalPoint3D_AffineComb    (const TQ3RationalPoint3D * points3D,
  545.                                  const float *            weights,
  546.                                  unsigned long             numPoints,
  547.                                  TQ3RationalPoint3D *    result);
  548.  
  549. EXTERN_API_C( TQ3Point3D *)
  550. Q3Point3D_AffineComb            (const TQ3Point3D *        points3D,
  551.                                  const float *            weights,
  552.                                  unsigned long             numPoints,
  553.                                  TQ3Point3D *            result);
  554.  
  555. EXTERN_API_C( TQ3RationalPoint4D *)
  556. Q3RationalPoint4D_AffineComb    (const TQ3RationalPoint4D * points4D,
  557.                                  const float *            weights,
  558.                                  unsigned long             numPoints,
  559.                                  TQ3RationalPoint4D *    result);
  560.  
  561.  
  562. /******************************************************************************
  563.  **                                                                             **
  564.  **                                Matrix Functions                             **
  565.  **                                                                             **
  566.  *****************************************************************************/
  567. EXTERN_API_C( TQ3Matrix3x3 *)
  568. Q3Matrix3x3_Copy                (const TQ3Matrix3x3 *    matrix3x3,
  569.                                  TQ3Matrix3x3 *            result);
  570.  
  571. EXTERN_API_C( TQ3Matrix4x4 *)
  572. Q3Matrix4x4_Copy                (const TQ3Matrix4x4 *    matrix4x4,
  573.                                  TQ3Matrix4x4 *            result);
  574.  
  575.  
  576. EXTERN_API_C( TQ3Matrix3x3 *)
  577. Q3Matrix3x3_SetIdentity            (TQ3Matrix3x3 *            matrix3x3);
  578.  
  579. EXTERN_API_C( TQ3Matrix4x4 *)
  580. Q3Matrix4x4_SetIdentity            (TQ3Matrix4x4 *            matrix4x4);
  581.  
  582.  
  583. EXTERN_API_C( TQ3Matrix3x3 *)
  584. Q3Matrix3x3_Transpose            (const TQ3Matrix3x3 *    matrix3x3,
  585.                                  TQ3Matrix3x3 *            result);
  586.  
  587. EXTERN_API_C( TQ3Matrix4x4 *)
  588. Q3Matrix4x4_Transpose            (const TQ3Matrix4x4 *    matrix4x4,
  589.                                  TQ3Matrix4x4 *            result);
  590.  
  591.  
  592. EXTERN_API_C( TQ3Matrix3x3 *)
  593. Q3Matrix3x3_Invert                (const TQ3Matrix3x3 *    matrix3x3,
  594.                                  TQ3Matrix3x3 *            result);
  595.  
  596. EXTERN_API_C( TQ3Matrix4x4 *)
  597. Q3Matrix4x4_Invert                (const TQ3Matrix4x4 *    matrix4x4,
  598.                                  TQ3Matrix4x4 *            result);
  599.  
  600.  
  601. EXTERN_API_C( TQ3Matrix3x3 *)
  602. Q3Matrix3x3_Adjoint                (const TQ3Matrix3x3 *    matrix3x3,
  603.                                  TQ3Matrix3x3 *            result);
  604.  
  605.  
  606. EXTERN_API_C( TQ3Matrix3x3 *)
  607. Q3Matrix3x3_Multiply            (const TQ3Matrix3x3 *    matrixA,
  608.                                  const TQ3Matrix3x3 *    matrixB,
  609.                                  TQ3Matrix3x3 *            result);
  610.  
  611. EXTERN_API_C( TQ3Matrix4x4 *)
  612. Q3Matrix4x4_Multiply            (const TQ3Matrix4x4 *    matrixA,
  613.                                  const TQ3Matrix4x4 *    matrixB,
  614.                                  TQ3Matrix4x4 *            result);
  615.  
  616.  
  617. EXTERN_API_C( TQ3Matrix3x3 *)
  618. Q3Matrix3x3_SetTranslate        (TQ3Matrix3x3 *            matrix3x3,
  619.                                  float                     xTrans,
  620.                                  float                     yTrans);
  621.  
  622. EXTERN_API_C( TQ3Matrix3x3 *)
  623. Q3Matrix3x3_SetScale            (TQ3Matrix3x3 *            matrix3x3,
  624.                                  float                     xScale,
  625.                                  float                     yScale);
  626.  
  627.  
  628. EXTERN_API_C( TQ3Matrix3x3 *)
  629. Q3Matrix3x3_SetRotateAboutPoint    (TQ3Matrix3x3 *            matrix3x3,
  630.                                  const TQ3Point2D *        origin,
  631.                                  float                     angle);
  632.  
  633. EXTERN_API_C( TQ3Matrix4x4 *)
  634. Q3Matrix4x4_SetTranslate        (TQ3Matrix4x4 *            matrix4x4,
  635.                                  float                     xTrans,
  636.                                  float                     yTrans,
  637.                                  float                     zTrans);
  638.  
  639. EXTERN_API_C( TQ3Matrix4x4 *)
  640. Q3Matrix4x4_SetScale            (TQ3Matrix4x4 *            matrix4x4,
  641.                                  float                     xScale,
  642.                                  float                     yScale,
  643.                                  float                     zScale);
  644.  
  645.  
  646. EXTERN_API_C( TQ3Matrix4x4 *)
  647. Q3Matrix4x4_SetRotateAboutPoint    (TQ3Matrix4x4 *            matrix4x4,
  648.                                  const TQ3Point3D *        origin,
  649.                                  float                     xAngle,
  650.                                  float                     yAngle,
  651.                                  float                     zAngle);
  652.  
  653. EXTERN_API_C( TQ3Matrix4x4 *)
  654. Q3Matrix4x4_SetRotateAboutAxis    (TQ3Matrix4x4 *            matrix4x4,
  655.                                  const TQ3Point3D *        origin,
  656.                                  const TQ3Vector3D *    orientation,
  657.                                  float                     angle);
  658.  
  659. EXTERN_API_C( TQ3Matrix4x4 *)
  660. Q3Matrix4x4_SetRotate_X            (TQ3Matrix4x4 *            matrix4x4,
  661.                                  float                     angle);
  662.  
  663. EXTERN_API_C( TQ3Matrix4x4 *)
  664. Q3Matrix4x4_SetRotate_Y            (TQ3Matrix4x4 *            matrix4x4,
  665.                                  float                     angle);
  666.  
  667. EXTERN_API_C( TQ3Matrix4x4 *)
  668. Q3Matrix4x4_SetRotate_Z            (TQ3Matrix4x4 *            matrix4x4,
  669.                                  float                     angle);
  670.  
  671. EXTERN_API_C( TQ3Matrix4x4 *)
  672. Q3Matrix4x4_SetRotate_XYZ        (TQ3Matrix4x4 *            matrix4x4,
  673.                                  float                     xAngle,
  674.                                  float                     yAngle,
  675.                                  float                     zAngle);
  676.  
  677. EXTERN_API_C( TQ3Matrix4x4 *)
  678. Q3Matrix4x4_SetRotateVectorToVector (TQ3Matrix4x4 *        matrix4x4,
  679.                                  const TQ3Vector3D *    v1,
  680.                                  const TQ3Vector3D *    v2);
  681.  
  682. EXTERN_API_C( TQ3Matrix4x4 *)
  683. Q3Matrix4x4_SetQuaternion        (TQ3Matrix4x4 *            matrix,
  684.                                  const TQ3Quaternion *    quaternion);
  685.  
  686. EXTERN_API_C( float )
  687. Q3Matrix3x3_Determinant            (const TQ3Matrix3x3 *    matrix3x3);
  688.  
  689. EXTERN_API_C( float )
  690. Q3Matrix4x4_Determinant            (const TQ3Matrix4x4 *    matrix4x4);
  691.  
  692.  
  693. /******************************************************************************
  694.  **                                                                             **
  695.  **                                Quaternion Routines                             **
  696.  **                                                                             **
  697.  *****************************************************************************/
  698. EXTERN_API_C( TQ3Quaternion *)
  699. Q3Quaternion_Set                (TQ3Quaternion *        quaternion,
  700.                                  float                     w,
  701.                                  float                     x,
  702.                                  float                     y,
  703.                                  float                     z);
  704.  
  705. EXTERN_API_C( TQ3Quaternion *)
  706. Q3Quaternion_SetIdentity        (TQ3Quaternion *        quaternion);
  707.  
  708. EXTERN_API_C( TQ3Quaternion *)
  709. Q3Quaternion_Copy                (const TQ3Quaternion *    quaternion,
  710.                                  TQ3Quaternion *        result);
  711.  
  712. EXTERN_API_C( TQ3Boolean )
  713. Q3Quaternion_IsIdentity            (const TQ3Quaternion *    quaternion);
  714.  
  715. EXTERN_API_C( TQ3Quaternion *)
  716. Q3Quaternion_Invert                (const TQ3Quaternion *    quaternion,
  717.                                  TQ3Quaternion *        result);
  718.  
  719. EXTERN_API_C( TQ3Quaternion *)
  720. Q3Quaternion_Normalize            (const TQ3Quaternion *    quaternion,
  721.                                  TQ3Quaternion *        result);
  722.  
  723. EXTERN_API_C( float )
  724. Q3Quaternion_Dot                (const TQ3Quaternion *    q1,
  725.                                  const TQ3Quaternion *    q2);
  726.  
  727. EXTERN_API_C( TQ3Quaternion *)
  728. Q3Quaternion_Multiply            (const TQ3Quaternion *    q1,
  729.                                  const TQ3Quaternion *    q2,
  730.                                  TQ3Quaternion *        result);
  731.  
  732. EXTERN_API_C( TQ3Quaternion *)
  733. Q3Quaternion_SetRotateAboutAxis    (TQ3Quaternion *        quaternion,
  734.                                  const TQ3Vector3D *    axis,
  735.                                  float                     angle);
  736.  
  737. EXTERN_API_C( TQ3Quaternion *)
  738. Q3Quaternion_SetRotate_XYZ        (TQ3Quaternion *        quaternion,
  739.                                  float                     xAngle,
  740.                                  float                     yAngle,
  741.                                  float                     zAngle);
  742.  
  743. EXTERN_API_C( TQ3Quaternion *)
  744. Q3Quaternion_SetRotate_X        (TQ3Quaternion *        quaternion,
  745.                                  float                     angle);
  746.  
  747. EXTERN_API_C( TQ3Quaternion *)
  748. Q3Quaternion_SetRotate_Y        (TQ3Quaternion *        quaternion,
  749.                                  float                     angle);
  750.  
  751. EXTERN_API_C( TQ3Quaternion *)
  752. Q3Quaternion_SetRotate_Z        (TQ3Quaternion *        quaternion,
  753.                                  float                     angle);
  754.  
  755.  
  756. EXTERN_API_C( TQ3Quaternion *)
  757. Q3Quaternion_SetMatrix            (TQ3Quaternion *        quaternion,
  758.                                  const TQ3Matrix4x4 *    matrix);
  759.  
  760. EXTERN_API_C( TQ3Quaternion *)
  761. Q3Quaternion_SetRotateVectorToVector (TQ3Quaternion *    quaternion,
  762.                                  const TQ3Vector3D *    v1,
  763.                                  const TQ3Vector3D *    v2);
  764.  
  765. EXTERN_API_C( TQ3Quaternion *)
  766. Q3Quaternion_MatchReflection    (const TQ3Quaternion *    q1,
  767.                                  const TQ3Quaternion *    q2,
  768.                                  TQ3Quaternion *        result);
  769.  
  770. EXTERN_API_C( TQ3Quaternion *)
  771. Q3Quaternion_InterpolateFast    (const TQ3Quaternion *    q1,
  772.                                  const TQ3Quaternion *    q2,
  773.                                  float                     t,
  774.                                  TQ3Quaternion *        result);
  775.  
  776. EXTERN_API_C( TQ3Quaternion *)
  777. Q3Quaternion_InterpolateLinear    (const TQ3Quaternion *    q1,
  778.                                  const TQ3Quaternion *    q2,
  779.                                  float                     t,
  780.                                  TQ3Quaternion *        result);
  781.  
  782. EXTERN_API_C( TQ3Vector3D *)
  783. Q3Vector3D_TransformQuaternion    (const TQ3Vector3D *    vector3D,
  784.                                  const TQ3Quaternion *    quaternion,
  785.                                  TQ3Vector3D *            result);
  786.  
  787. EXTERN_API_C( TQ3Point3D *)
  788. Q3Point3D_TransformQuaternion    (const TQ3Point3D *        point3D,
  789.                                  const TQ3Quaternion *    quaternion,
  790.                                  TQ3Point3D *            result);
  791.  
  792.  
  793. /******************************************************************************
  794.  **                                                                             **
  795.  **                                Volume Routines                                 **
  796.  **                                                                             **
  797.  *****************************************************************************/
  798. EXTERN_API_C( TQ3BoundingBox *)
  799. Q3BoundingBox_Copy                (const TQ3BoundingBox *    src,
  800.                                  TQ3BoundingBox *        dest);
  801.  
  802. EXTERN_API_C( TQ3BoundingBox *)
  803. Q3BoundingBox_Union                (const TQ3BoundingBox *    v1,
  804.                                  const TQ3BoundingBox *    v2,
  805.                                  TQ3BoundingBox *        result);
  806.  
  807. EXTERN_API_C( TQ3BoundingBox *)
  808. Q3BoundingBox_Set                (TQ3BoundingBox *        bBox,
  809.                                  const TQ3Point3D *        min,
  810.                                  const TQ3Point3D *        max,
  811.                                  TQ3Boolean             isEmpty);
  812.  
  813. EXTERN_API_C( TQ3BoundingBox *)
  814. Q3BoundingBox_UnionPoint3D        (const TQ3BoundingBox *    bBox,
  815.                                  const TQ3Point3D *        point3D,
  816.                                  TQ3BoundingBox *        result);
  817.  
  818. EXTERN_API_C( TQ3BoundingBox *)
  819. Q3BoundingBox_UnionRationalPoint4D (const TQ3BoundingBox * bBox,
  820.                                  const TQ3RationalPoint4D * point4D,
  821.                                  TQ3BoundingBox *        result);
  822.  
  823. EXTERN_API_C( TQ3BoundingBox *)
  824. Q3BoundingBox_SetFromPoints3D    (TQ3BoundingBox *        bBox,
  825.                                  const TQ3Point3D *        points3D,
  826.                                  unsigned long             numPoints,
  827.                                  unsigned long             structSize);
  828.  
  829. EXTERN_API_C( TQ3BoundingBox *)
  830. Q3BoundingBox_SetFromRationalPoints4D (TQ3BoundingBox *    bBox,
  831.                                  const TQ3RationalPoint4D * points4D,
  832.                                  unsigned long             numPoints,
  833.                                  unsigned long             structSize);
  834.  
  835.  
  836. /******************************************************************************
  837.  **                                                                             **
  838.  **                                Sphere Routines                                 **
  839.  **                                                                             **
  840.  *****************************************************************************/
  841. EXTERN_API_C( TQ3BoundingSphere *)
  842. Q3BoundingSphere_Copy            (const TQ3BoundingSphere * src,
  843.                                  TQ3BoundingSphere *    dest);
  844.  
  845. EXTERN_API_C( TQ3BoundingSphere *)
  846. Q3BoundingSphere_Union            (const TQ3BoundingSphere * s1,
  847.                                  const TQ3BoundingSphere * s2,
  848.                                  TQ3BoundingSphere *    result);
  849.  
  850. EXTERN_API_C( TQ3BoundingSphere *)
  851. Q3BoundingSphere_Set            (TQ3BoundingSphere *    bSphere,
  852.                                  const TQ3Point3D *        origin,
  853.                                  float                     radius,
  854.                                  TQ3Boolean             isEmpty);
  855.  
  856. EXTERN_API_C( TQ3BoundingSphere *)
  857. Q3BoundingSphere_UnionPoint3D    (const TQ3BoundingSphere * bSphere,
  858.                                  const TQ3Point3D *        point3D,
  859.                                  TQ3BoundingSphere *    result);
  860.  
  861. EXTERN_API_C( TQ3BoundingSphere *)
  862. Q3BoundingSphere_UnionRationalPoint4D (const TQ3BoundingSphere * bSphere,
  863.                                  const TQ3RationalPoint4D * point4D,
  864.                                  TQ3BoundingSphere *    result);
  865.  
  866.  
  867. EXTERN_API_C( TQ3BoundingSphere *)
  868. Q3BoundingSphere_SetFromPoints3D (TQ3BoundingSphere *    bSphere,
  869.                                  const TQ3Point3D *        points3D,
  870.                                  unsigned long             numPoints,
  871.                                  unsigned long             structSize);
  872.  
  873. EXTERN_API_C( TQ3BoundingSphere *)
  874. Q3BoundingSphere_SetFromRationalPoints4D (TQ3BoundingSphere * bSphere,
  875.                                  const TQ3RationalPoint4D * points4D,
  876.                                  unsigned long             numPoints,
  877.                                  unsigned long             structSize);
  878.  
  879.  
  880.  
  881.  
  882.  
  883. #if PRAGMA_ENUM_ALWAYSINT
  884.     #pragma enumsalwaysint reset
  885. #elif PRAGMA_ENUM_OPTIONS
  886.     #pragma option enum=reset
  887. #elif defined(PRAGMA_ENUM_PACK__QD3DMATH__)
  888.     #pragma options(pack_enums)
  889. #endif
  890.  
  891. #if PRAGMA_STRUCT_ALIGN
  892.     #pragma options align=reset
  893. #elif PRAGMA_STRUCT_PACKPUSH
  894.     #pragma pack(pop)
  895. #elif PRAGMA_STRUCT_PACK
  896.     #pragma pack()
  897. #endif
  898.  
  899. #ifdef PRAGMA_IMPORT_OFF
  900. #pragma import off
  901. #elif PRAGMA_IMPORT
  902. #pragma import reset
  903. #endif
  904.  
  905. #ifdef __cplusplus
  906. }
  907. #endif
  908.  
  909. #endif /* __QD3DMATH__ */
  910.  
  911.